package com.hzy.pay.exception;

import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Map;

/**
 * 统一拦截异常
 *
 * @author yanlin
 * @version v1.3
 * @date 2018-10-18 下午2:27
 * @since v8.0
 **/
@RestControllerAdvice
public class GlobalDefultExceptionHandler {
    /**
     * 处理参数异常，一般用于校验body参数
     *
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object globalException(Exception e) {
        Map<String, Object> result = Maps.newConcurrentMap();
        result.put("code", 400);
        result.put("message", e.getMessage());
        return result;
    }
}

